package com.smh.demo1.a20;

import org.springframework.format.Formatter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * @author shiminghui
 * @date 2025/5/1 16:45
 * @description: TODO
 */
public class MyDateFormatter implements Formatter<Date> {
    private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy|MM|dd");

    public static void main(String[] args) throws ParseException {
        MyDateFormatter myDateFormatter = new MyDateFormatter();
        Object parse = myDateFormatter.parse("2004|10|26", null);
        System.out.println(parse);

    }

    @Override
    public Date parse(String text, Locale locale) throws ParseException {
        Date result = simpleDateFormat.parse(text);
        return result;
    }

    @Override
    public String print(Date object, Locale locale) {
        String format = simpleDateFormat.format(object);
        return format;
    }
}
